package com.youxin.busfoundation.common;

import java.util.Random;

import org.springframework.core.env.Environment;

import com.youxin.busfoundation.enums.LogFlagType;

/**
 * 配置信息
 * @author yingde.cao
 *
 */
public class BuildConfig {
	private static BuildConfig config=new BuildConfig();
	
	public static BuildConfig instance(){
		return config;
	}

	public static void initWithEnvid(Environment env)
	{
		config.setEnvid(env.getProperty("spring.profiles.active"));		
	}
	
	private String envid;

	public String getEnvid() {
		return envid;
	}

	public void setEnvid(String envid) {
		this.envid = envid;
	}
	
	public static boolean isProduction(){
		return "pro".equalsIgnoreCase(config.getEnvid());
	}
	
	public static boolean isPreProduction(){
		return "prepro".equalsIgnoreCase(config.getEnvid());
	}
	
	public static boolean isTest()
	{
		return isTestLocal()||isTestPro();
	}
	
	public static boolean isTestLocal(){
		return "testlocal".equalsIgnoreCase(config.getEnvid());
	}
	
	public static boolean isTestPro(){
		return "testpro".equalsIgnoreCase(config.getEnvid());
	}
	
	public static boolean isDebug(){
		return !(isPreProduction()||isProduction());
	}
	
	public static LogFlagType getFlagType(){
		if(isProduction())
		{
			return LogFlagType.Production;
		}
		if(isPreProduction())
		{
			return LogFlagType.PreProduction;
		}
		if(isTestLocal())
		{
			return LogFlagType.TestLocal;
		}
		if(isTestPro())
		{
			return LogFlagType.TestPro;
		}
		return LogFlagType.Develop;		
	}
	
	
}
